package com.jack.lib

import android.Manifest
import android.graphics.Typeface
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.lifecycleScope
import com.blankj.utilcode.util.FragmentUtils
import com.jack.lib.base.BaseActivity
import com.jack.lib.base.header.HeaderConfigurator
import com.jack.lib.base.header.IconType
import com.jack.lib.databinding.ActivityMainBinding
import com.jack.lib.net.ApiManager
import com.jack.lib.net.ext.net
import com.jack.lib.core.net.ZipNetResult
import com.jack.lib.core.utils.JLog
import com.jack.lib.net.download.download
import kotlinx.coroutines.launch


class MainActivity : BaseActivity<ActivityMainBinding>() {

    override fun onCreateView(savedInstanceState: Bundle?) {
//        val apiService = JNetManager.createService(ApiService::class.java)
//        binding.viewPager2.adapter = JPFragmentAdapter(supportFragmentManager, lifecycle, mutableListOf(MainFragment()))
//        binding.viewPager2.offscreenPageLimit = 2
//        FragmentUtils.add(supportFragmentManager, MainFragment(), binding.container.id)
        FragmentUtils.add(supportFragmentManager, MainFragment(), binding.container.id)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(arrayOf(Manifest.permission.ACCESS_NETWORK_STATE), 1)
        }

        net { ApiManager.api.login(mapOf("id" to "1")) }.onSuccess {

        }

        lifecycleScope.launch {

            val result1 = net { ApiManager.api.login(mapOf()) }.get()
            val result2 = net { ApiManager.api.login3(mapOf()) }.get()
            val result3 = net { ApiManager.api.login4(mapOf()) }.get()

            result1.allSuccess(result2, result3) {

            }
        }
    }

    override fun initHeader(config: HeaderConfigurator) {
        config[IconType.BACK]?.click = { finish() }
        config[IconType.RIGHT]?.click = { finish() }
        config[IconType.TITLE]?.text = "柚子牛B"
        config[IconType.TITLE]?.typeface = Typeface.DEFAULT_BOLD
    }
}
